﻿using System;
using System.Windows.Forms;

namespace EyFramework.Library.Select
{
    public partial class FrmDevSelect : FrmDevBase
    {
        public FrmDevSelect()
        {
            InitializeComponent();
        }

        private void FrmDevSelect_Load(object sender, EventArgs e)
        {
            gcData.Focus();
            QueryData();
            gvData.FocusedRowHandle = 0;
            if (gvData.RowCount == 1)
            {
                btnSure_Click(null, null);
            }
            gcData.Select();
        }

        /// <summary>
        /// 根据条件查询数据
        /// </summary>
        protected virtual void QueryData()
        {
        }

        public virtual object GetSelectData()
        {
            if (gvData.FocusedRowHandle >= 0)
            {
                return gvData.GetRow(gvData.FocusedRowHandle);
            }
            else
            {
                return null;
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        private void btnSure_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}